package ui;

import javabean.House;
import service.imp.ServiceLogicImp;

import java.util.ArrayList;
import java.util.Scanner;

public class Show {
    public static void view(){
        ArrayList<House> houses = new ArrayList<>();
        ServiceLogicImp serviceLogicImp = new ServiceLogicImp();
        System.out.println("---------欢迎使用房屋出租系统---------");
        while(true) {
            try {
                Scanner scanner = new Scanner(System.in);
                System.out.println("1.新增房源");
                System.out.println("2.查找房屋");
                System.out.println("3.删除房屋");
                System.out.println("4.修改房屋信息");
                System.out.println("5.房屋列表");
                System.out.println("6.退出");
                System.out.println("---------请输入你要进行的操作：---------");
                int menu = scanner.nextInt();//输入的不是数字时会抛出异常
                scanner.nextLine();
                switch (menu) {
                    case 1:
                        serviceLogicImp.addService();
                        break;
                    case 2:
                        System.out.println("请输入你要查找的房屋编号：");
                        int id1 = scanner.nextInt();
                        House service = serviceLogicImp.findService(id1);
                        if(service==null){
                            System.out.println("你要查找的房屋不存在！");
                        }
                        break;
                    case 3:
                        System.out.println("请输入你要删除的房屋编号：");
                        int id2 = scanner.nextInt();
                        Integer integer = serviceLogicImp.delService(id2);
                        if(integer>0){
                            System.out.println("---成功删除"+integer+"条对象---");
                        }else{
                            System.out.println("---删除失败---");
                        }
                        break;
                    case 4:
                        System.out.println("请输入你要修改的房屋编号：");
                        int id3 = scanner.nextInt();
                        serviceLogicImp.updateService(id3);
                        break;
                    case 5:
                        serviceLogicImp.listService();
                        break;
                    case 6:
                        System.out.println("请输入你的选择(Y/N)：");
                        String next = scanner.next();
                        if(next.equals("Y")){
                            System.out.println("你退出了程序~");
                            System.exit(0);
                        }else if(next.equals("N")){
                            System.out.println("请继续你的操作");
                        }else{
                            System.out.println("非正确指令，请重新输入！");
                        }
                        break;
                    default:
                        System.out.println("无效指令，请重新输入！");
                        break;
                }
            } catch (Exception e) {
//                throw new RuntimeException(e);
                System.out.println("你是不是心情不好！");
                continue;
            }
        }
    }
}
